//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#include <buola/algorithm/split.h>
#include <clocale>
#include <buola/io.h>
#include <unicode/uchar.h>
#include <unicode/uloc.h>
#include <iostream>

int main()
{
    using namespace buola;
    std::locale::global(std::locale(""));
    msg_info() << std::setlocale(LC_ALL,nullptr) << "\n";
    msg_info() << std::locale().name() << "\n";
    msg_info() << uloc_getDefault() << "\n" << nFlush;
    
//    std::u16string lString(L"ñññññññññññññññññññññññññññññññññññññññ  ññññññññ ñññ ñññ ññññññ  ñññññññññññ ñññññ ");

    int lC=0;
    start_timer();
    for(wchar_t i=0;i<0x1ffff;i++)
    {
        if(iswlower(towlower(i)))
            lC++;
            
    }
    end_timer();
    std::cout << lC << "\n";

    lC=0;
    start_timer();
    for(wchar_t i=0;i<0x1ffff;i++)
    {
        if(u_islower(u_tolower(i)))
            lC++;
    }
    end_timer();
    std::cout << lC << "\n";
    
    lC=0;
    start_timer();
    for(wchar_t i=0;i<0x1ffff;i++)
    {
        if(u_isULowercase(u_tolower(i)))
            lC++;
    }
    end_timer();
    std::cout << lC << "\n";
    
    lC=0;
    start_timer();
    for(wchar_t i=0;i<0x1ffff;i++)
    {
        if(u_hasBinaryProperty(u_tolower(i),UCHAR_LOWERCASE))
            lC++;
    }
    end_timer();
    std::cout << lC << "\n";
    
    lC=0;
    const auto &lFacet=std::use_facet<std::ctype<wchar_t>>(std::locale());
    start_timer();
    for(wchar_t i=0;i<0x1ffff;i++)
    {
        if(lFacet.is(std::ctype_base::lower,(lFacet.tolower(i))))
            lC++;
    }
    end_timer();
    std::cout << lC << "\n";
    
    std::wstring lWString(20000,'a');
    std::u16string lU16String(20000,'a');
    for(int i=0;i<20000;i++)
    {
        lWString[i]=i+1;
        lU16String[i]=i+1;
    }
    
    start_timer();
    std::string lString=utf8(lWString);
    end_timer();
    std::cout << lString.length() << "\n";

    start_timer();
    lString=utf8(lWString);
    end_timer();
    std::cout << lString.length() << "\n";

    start_timer();
    lString=utf8(lWString);
    end_timer();
    std::cout << lString.length() << "\n";

    start_timer();
    std::string lString2=utf8(lU16String);
    end_timer();
    std::cout << lString2.length() << "\n";

    start_timer();
    lWString=utf32(lString);
    end_timer();
    std::cout << lWString.length() << "\n";

    start_timer();
    lU16String=utf16(lString2);
    end_timer();
    std::cout << lU16String.length() << "\n";
}
